from rest_framework import serializers
from complaints.models import Spit



# class SpitSerializer(serializers.ModelSerializer):
#     # nickname = serializers.StringRelatedField()
#     user = serializers.StringRelatedField()
#     # nickname = user
#     user_id = serializers.ImageField()
#     # avatar = serializers.ImageField(required=False)
#     parent = serializers.IntegerField()
#
#     class Meta:
#         model = Spit
#         fields = ("id","content","publishtime","nickname","user_id",
#                   "visits","thumbup","share","comment","state","avatar",
#                   "collected","hasthumbup","parent")



class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = Spit
        fields='__all__'


class SpitSerializer(serializers.ModelSerializer):

    user_id = serializers.IntegerField(required=False)

    avatar = serializers.ImageField(label='用户头像', max_length=100, required=False)

    parent = serializers.StringRelatedField(required=False)
    parent_id = serializers.IntegerField(required=False)

    class Meta:
        model = Spit
        fields = ("id", "content", "publishtime", "nickname", "user_id",
                  "visits", "thumbup", "comment", "avatar",
                  "collected", "hasthumbup", "parent",'parent_id')
